package com.dianping.cat.home.service.client.transform;

import com.dianping.cat.home.service.client.entity.ClientReport;
import com.dianping.cat.home.service.client.entity.Domain;
import com.dianping.cat.home.service.client.entity.Method;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.xml.sax.Attributes;











public class DefaultSaxMaker
  extends Object
  implements IMaker<Attributes>
{
  public ClientReport buildClientReport(Attributes attributes) {
/*  26 */     String domain = attributes.getValue("domain");
/*  27 */     String startTime = attributes.getValue("start-time");
/*  28 */     String endTime = attributes.getValue("end-time");
    ClientReport clientReport = new ClientReport(domain);

    if (startTime != null) {
      clientReport.setStartTime(toDate(startTime, "yyyy-MM-dd HH:mm:ss", null));
    }

/*  35 */     if (endTime != null) {
      clientReport.setEndTime(toDate(endTime, "yyyy-MM-dd HH:mm:ss", null));
    }

/*  39 */     return clientReport;
  }


  public Domain buildDomain(Attributes attributes) {
/*  44 */     String id = attributes.getValue("id");
/*  45 */     String totalCount = attributes.getValue("totalCount");
/*  46 */     String failureCount = attributes.getValue("failureCount");
/*  47 */     String failurePercent = attributes.getValue("failurePercent");
/*  48 */     String sum = attributes.getValue("sum");
/*  49 */     String avg = attributes.getValue("avg");
/*  50 */     Domain domain = new Domain(id);

/*  52 */     if (totalCount != null) {
/*  53 */       domain.setTotalCount(((Long)convert(Long.class, totalCount, Long.valueOf(0L))).longValue());
    }

/*  56 */     if (failureCount != null) {
/*  57 */       domain.setFailureCount(((Long)convert(Long.class, failureCount, Long.valueOf(0L))).longValue());
    }

/*  60 */     if (failurePercent != null) {
/*  61 */       domain.setFailurePercent(((Double)convert(Double.class, failurePercent, Double.valueOf(0.0D))).doubleValue());
    }

/*  64 */     if (sum != null) {
/*  65 */       domain.setSum(((Double)convert(Double.class, sum, Double.valueOf(0.0D))).doubleValue());
    }

/*  68 */     if (avg != null) {
/*  69 */       domain.setAvg(((Double)convert(Double.class, avg, Double.valueOf(0.0D))).doubleValue());
    }

/*  72 */     return domain;
  }


  public Method buildMethod(Attributes attributes) {
/*  77 */     String id = attributes.getValue("id");
    String service = attributes.getValue("service");
/*  79 */     String totalCount = attributes.getValue("totalCount");
/*  80 */     String failureCount = attributes.getValue("failureCount");
/*  81 */     String failurePercent = attributes.getValue("failurePercent");
/*  82 */     String sum = attributes.getValue("sum");
/*  83 */     String avg = attributes.getValue("avg");
/*  84 */     String qps = attributes.getValue("qps");
/*  85 */     String timeout = attributes.getValue("timeout");
/*  86 */     Method method = new Method(id);

/*  88 */     if (service != null) {
/*  89 */       method.setService(service);
    }

/*  92 */     if (totalCount != null) {
/*  93 */       method.setTotalCount(((Long)convert(Long.class, totalCount, Long.valueOf(0L))).longValue());
    }

/*  96 */     if (failureCount != null) {
/*  97 */       method.setFailureCount(((Long)convert(Long.class, failureCount, Long.valueOf(0L))).longValue());
    }

/* 100 */     if (failurePercent != null) {
/* 101 */       method.setFailurePercent(((Double)convert(Double.class, failurePercent, Double.valueOf(0.0D))).doubleValue());
    }

/* 104 */     if (sum != null) {
/* 105 */       method.setSum(((Double)convert(Double.class, sum, Double.valueOf(0.0D))).doubleValue());
    }

/* 108 */     if (avg != null) {
/* 109 */       method.setAvg(((Double)convert(Double.class, avg, Double.valueOf(0.0D))).doubleValue());
    }

/* 112 */     if (qps != null) {
/* 113 */       method.setQps(((Double)convert(Double.class, qps, Double.valueOf(0.0D))).doubleValue());
    }

/* 116 */     if (timeout != null) {
/* 117 */       method.setTimeout(((Double)convert(Double.class, timeout, Double.valueOf(0.0D))).doubleValue());
    }

/* 120 */     return method;
  }


  protected <T> T convert(Class<T> type, String value, T defaultValue) {
/* 125 */     if (value == null || value.length() == 0) {
/* 126 */       return defaultValue;
    }

/* 129 */     if (type == Boolean.class || type == boolean.class)
/* 130 */       return (T)Boolean.valueOf(value); 
/* 131 */     if (type == Integer.class || type == int.class)
/* 132 */       return (T)Integer.valueOf(value); 
/* 133 */     if (type == Long.class || type == long.class)
/* 134 */       return (T)Long.valueOf(value); 
/* 135 */     if (type == Short.class || type == short.class)
/* 136 */       return (T)Short.valueOf(value); 
/* 137 */     if (type == Float.class || type == float.class)
/* 138 */       return (T)Float.valueOf(value); 
/* 139 */     if (type == Double.class || type == double.class)
/* 140 */       return (T)Double.valueOf(value); 
/* 141 */     if (type == Byte.class || type == byte.class)
/* 142 */       return (T)Byte.valueOf(value); 
/* 143 */     if (type == Character.class || type == char.class) {
/* 144 */       return (T)Character.valueOf(value.charAt(0));
    }
/* 146 */     return (T)value;
  }


  protected Date toDate(String str, String format, Date defaultValue) {
/* 151 */     if (str == null || str.length() == 0) {
/* 152 */       return defaultValue;
    }

    try {
/* 156 */       return (new SimpleDateFormat(format)).parse(str);
/* 157 */     } catch (ParseException e) {
/* 158 */       throw new RuntimeException(String.format("Unable to parse date(%s) in format(%s)!", new Object[] { str, format }), e);
    }
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/classes/!/com/dianping/cat/home/service/client/transform/DefaultSaxMaker.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */